'use strict';

angular.module('Hospital.second', ['ngRoute', 'Hospital.services'])

.config(['$routeProvider', function($routeProvider) {
	
	console.log($routeProvider);
	$routeProvider.when('/second', {
		templateUrl: 'views/second/second.html'
	});		
}])

.controller('callHistoryCtrl', ['$location', '$http', '$scope', function($location, $http, $scope) {
	$scope.params = Object.create($scope.config.defaultPageInfo);

	$scope.setVideo = function(){
		//console.log(document.getElementsByTagName("audio"));
		//document.getElementById("mp3URL").setAttribute("src",'music/1.m4a');
	};
	$scope.getPage = function(pn) {
		if(!isNaN(pn)) {
			if($scope.params.pn === pn || pn <=0 || pn > $scope.params.pc) {
				return;
			}
			$scope.params.pn = pn;
		}
		$http.post(API_SERVER + 'callHistory/list', $scope.params).success(function(res) {
			console.log(res);
			if (res && res.code === 0) {
				$scope.params.pn =res.pageNo;
				$scope.params.pc = res.pageCnt;

				$scope.callHistoryList = res.dataList;
				$scope.historyStatusMap = {
					'0':'未派单',
					'1':'已派单',
					'2':'已完成'
				};
			}
		});
	};
	$scope.getPage();
	$scope.setVideo();


}])
.controller('engineerCtrl', ['$location', '$http', '$scope', function($location, $http, $scope) {
	$scope.params = Object.create($scope.config.defaultPageInfo);
	$scope.getPage = function(pn) {
		if(!isNaN(pn)) {
			if($scope.params.pn === pn || pn <=0 || pn > $scope.params.pc) {
				return;
			}
			$scope.params.pn = pn;
		}
		$http.post(API_SERVER + 'engineer/list', $scope.params).success(function(res) {
			console.log(res);
			if (res && res.code === 0) {
				$scope.params.pn =res.pageNo;
				$scope.params.pc = res.pageCnt;

				$scope.engineerList = res.dataList;


			}
		});
	};
	$scope.getPage();
}])
.controller('workOrderCtrl', ['$location', '$http', '$scope', function($location, $http, $scope) {
	$scope.params = Object.create($scope.config.defaultPageInfo);
	$scope.getPage = function(pn) {
		if(!isNaN(pn)) {
			if($scope.params.pn === pn || pn <=0 || pn > $scope.params.pc) {
				return;
			}
			$scope.params.pn = pn;
		}
		$http.post(API_SERVER + 'workOrder/list', $scope.params).success(function(res) {
			console.log(res);
			if (res && res.code === 0) {
				$scope.params.pn =res.pageNo;
				$scope.params.pc = res.pageCnt;

				$scope.workOrderList = res.dataList;
				$scope.orderStatusMap = {
					    '-1':"已终止",
						'0':'未指派',
						'1':'已指派',
						'2':'已解决',
						'3':'已抵达',
						'4':'已暂停'
				};

			}
			$scope.orderCount = $scope.workOrderList.length;
			$scope.resolveCount = 0;
			$scope.assignCount = 0;
			$scope.noAssignCount = 0;
			$scope.arrivedCount = 0;
			$scope.endCount = 0;
			$scope.pauseCount = 0;
			$scope.finishedCount = 0;
			for (var i = 0; i < $scope.workOrderList.length; i++) {
				var workOrder = $scope.workOrderList[i];
				if(workOrder.orderStatus==-1){
					$scope.endCount+=1;
				}else if(workOrder.orderStatus==0){
					$scope.noAssignCount+=1;
				}else if(workOrder.orderStatus==1){
					$scope.assignCount+=1;
				}else if(workOrder.orderStatus==2){
					$scope.finishedCount+=1;
				}else if(workOrder.orderStatus==3){
					$scope.arrivedCount+=1;
				}else if(workOrder.orderStatus==4){
					$scope.pauseCount+=1;
				}

			}
		});
	};
	$scope.getPage();

	
}]);